﻿using System.Linq;
using Sessionizer.Core;
using Sessionizer.Samples.Model;

namespace Sessionizer.Samples.Sessionized.Rankers.InitalOrder
{
    /// <summary>
    /// Ranker depends on Session's data values
    /// Provides ranks based on order of elements in initial ITeamCollection
    /// This is only ranker that need to know that there are sessions in our world.
    /// </summary>
    public sealed class InitalOrderRanker:IRanker
    {
        private readonly ISessions<ITeamCollection> _teams;
        private readonly ISessions<ITopCount> _topCount;

        /// <summary>
        /// Constructor resolves session data
        /// </summary>
        /// <param name="teams">Resolves wrapper containing instance, registred via session.Set(teams) call.</param>
        /// <param name="topCount">Resolves wrapper containing instance regirtred via session.Set(count) call. </param>
        public InitalOrderRanker(
            ISessions<ITeamCollection> teams,
            ISessions<ITopCount> topCount
            )
        {
            _teams = teams;
            _topCount = topCount;
        }

        public int Rank(ITeam team)
        {
            return _teams.Instance.ToList().IndexOf(team)+_topCount.Instance.Count;
        }
    }
}